package com.yun.algorithmproblem.leetcode;

public class Leetcode2264 {

    public static void main(String[] args) {
        Leetcode2264 obj=new Leetcode2264();
        String s="014455";
        System.out.println(obj.largestGoodInteger(s));
    }

    public String largestGoodInteger(String num) {
        int prev=-1;
        int cnt=1;
        int ans=-1;
        for (int i = 0; i < num.length(); i++) {
            int curr = num.charAt(i)-48;
            System.out.println(curr);
            if(curr==prev){
                cnt++;
                if(cnt==3){
                    if(curr==9){
                        return "999";
                    }
                    ans=Math.max(ans,curr);
                }
            }else {
                cnt=1;
            }
            prev=curr;
        }
        if(ans==-1){
            return "";
        }
        StringBuilder sb=new StringBuilder();
        sb.append(ans).append(ans).append(ans);
        return sb.toString();
    }
}
